The present invention relates to a gas detector for measuring one or more hydrocarbons or some other gas having its infrared absorption spectrum partially or entirely overlapped with water and, in addition, carbon dioxide and/or nitrogen oxide, and to a method for removing the measurement-disturbing gases contained in a gas detector from that space or a part of that space remaining outside the measuring chamber, in which the electromagnetic radiation emitted from a radiation source travels to a radiation detector.